'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:TaskMytaskCtrl
 * @description
 * # TaskMytaskCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('TaskMytaskCtrl', function(openApi, localStorageService, $scope, $timeout, $rootScope, PagingService, $location) {
        // 初始化
        var vm = this;
        this.curtab = localStorageService.get("taskmenu") || 4;
        // 初始化过程
        this.subtabList = [{
            value: "未完成的",
            key: "4"
        },{
            value: "创建的",
            key: "1"
        }, {
            value: "负责的",
            key: "2"
        }, {
            value: "参与的",
            key: "3"
        }];
        this.statuslist = [{
            value: "1",
            key: "未完成"
        }, {
            value: "2",
            key: "已完成"
        }]
        this.showsearch = function() {
            vm.picker = {};
            vm.showCerPicker = true;
            $rootScope.$emit('showmasker');
        }
        vm.showSearch = function() {
            vm.picker = {};
            vm.showCerPicker = true;
            $rootScope.$emit('showmasker');
        }
        vm.cacelDialog = function() {
            vm.showCerPicker = false;
            $rootScope.$emit('closemasker');
        }
        $scope.$on('closemasker', function() {
            vm.cacelDialog()
        });
        vm.confirmDialog = function() {
            if (vm.picker.content || vm.picker.leaderName || vm.picker.status) {
                vm.initData(vm.picker);
            }
            vm.cacelDialog()
        };
        this.submenuhandle = function(key) {
            if (this.curtab == key) {
                return
            }
            this.curtab = key;
            vm.initData()
        }
        this.initData = function(options) {
            var param = angular.extend({}, options);
            param.flag = this.curtab
            vm.datalist = [];
            $timeout(function() {
                vm.datalist = new PagingService(openApi.worktask, param);
            }, 400)
        };
        this.initData();
        this.goDetail = function(item) {
            localStorageService.set("taskmenu", this.curtab);
            $location.path("task/taskdetail/" + item.pkId)
        }
        this.newtask = function() {
            $location.path("task/newtask")
        }
    });
